package com.chdwmp.product.controller;

import com.chdwmp.product.bean.Product;
import com.chdwmp.product.bean.CommonResponse;
import com.chdwmp.product.bean.backend.ProductSearchVo;
import com.chdwmp.product.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: LLL
 * @Date: 2021/3/6 21:04
 * @Description: 用户模块接口层
 */
@Api(description = "产品模块", tags = {"产品模块接口控制层"})
@RequestMapping("/products")
@RestController
public class ProductController {

    @Autowired
    ProductService productService;

    @PostMapping
    @ApiOperation(value = "新增产品", httpMethod = "POST", response = CommonResponse.class)
    public CommonResponse addProduct(@RequestBody Product product) throws Exception {
        productService.addProduct(product);
        return new CommonResponse();
    }

    @PostMapping("/updateProduct")
    @ApiOperation(value = "修改产品", httpMethod = "POST", response = CommonResponse.class)
    public CommonResponse updateProduct(@RequestBody Product product) throws Exception {
        productService.updateProduct(product);
        return new CommonResponse();
    }

    @PostMapping("/deleteProduct/{id}")
    @ApiOperation(value = "删除产品", httpMethod = "POST", response = CommonResponse.class)
    public CommonResponse deleteProduct(@PathVariable String id) throws Exception {
        productService.deleteProduct(id);
        return new CommonResponse();
    }

    @PostMapping("/getProductList")
    @ApiOperation(value = "获取产品列表", httpMethod = "POST", response = CommonResponse.class)
    public CommonResponse getProductList(@RequestBody  ProductSearchVo productSearchVo) throws Exception {

        return new CommonResponse(productService.getProductList(productSearchVo));
    }


}